// components/listCategory/listCategory.js
import request from '../../utils/request'
Component({
    
    options:{
        addGlobalClass:true
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },
        /**
     * 组件的初始数据
     */
         data: {
          yuzhonglist:[],   //语言
          fenggelist:[],    //风格
          changjinlist:[],  //场景
          qingganlist:[],   //情感
          zhutilist:[],      //主题
          categories:[],

        },
    lifetimes:{
        ready: function() {
            // console.log("执行")
        this.gettags()
        this.toggleDelay()
       },
    },

    /**
     * 组件的方法列表
     */
    methods: {
      async gettags(){
        let {           
                        yuzhonglist,   //语言
                        fenggelist,    //风格
                        changjinlist,  //场景
                        qingganlist,   //情感
                        zhutilist,      //主题
                        
        } = this.data   
        let catlist = await request('/playlist/catlist');
        let categories = catlist.categories
        let sub = catlist.sub
        sub.forEach((item , index) => {
            switch(item.category){
              case 0 : yuzhonglist.push(item.name);
                      break;
              case 1 : fenggelist.push(item.name);
                      break;
              case 2 : changjinlist.push(item.name);
                      break;
              case 3 : qingganlist.push(item.name);
                      break;
              case 4 : zhutilist.push(item.name);
                      break;
              
            }
        });
       
        this.setData({
            yuzhonglist,   //语言
            fenggelist,    //风格
            changjinlist,  //场景
            qingganlist,   //情感
            zhutilist,      //主题
            categories
        })
        // console.log(this.data.zhutilist)
       },
       //点击标签
       clitag(event) {
        
        let tag = event.currentTarget.dataset.name
        // console.log(tag);
        this.triggerEvent('cliTag', {
            tag
        })
      },


      toggleDelay() {
        var that = this;
        that.setData({
          toggleDelay: true
        })
        setTimeout(function() {
          that.setData({
            toggleDelay: false
          })
        }, 1000)
      },
    }
})
